import 'package:dio/dio.dart';
import 'package:psi/entity/purchass_entity.dart';
import 'package:psi/entity/request/login_req.dart';
import 'package:psi/entity/request/purchase_list_req.dart';
import 'package:psi/entity/request/register_req.dart';
import 'package:psi/entity/common_resp.dart';
import 'package:psi/entity/request/sales_list_req.dart';
import 'package:psi/entity/request/update_password_req.dart';
import 'package:psi/entity/response/add_sales_resp.dart';
import 'package:psi/entity/response/login_resp.dart';
import 'package:psi/entity/response/purchase_item_resp.dart';
import 'package:psi/entity/response/purchase_list_resp.dart';
import 'package:psi/entity/response/recent_names_list_resp.dart';
import 'package:psi/entity/response/sales_item_resp.dart';
import 'package:psi/entity/sales_entity.dart';
import 'package:retrofit/http.dart';

import '../entity/response/oss_sts_resp.dart';
import '../entity/response/purchase_statistics_resp.dart';
import '../entity/response/sales_list_resp.dart';
import '../entity/response/sales_statistics_resp.dart';


/// flutter pub run build_runner build --delete-conflicting-outputs

part 'service_api.g.dart';

@RestApi(baseUrl: "http://39.107.65.30:8888/psi")
abstract class RestClient {
  factory RestClient(Dio dio, {String baseUrl}) = _RestClient;

  // <------------      OssController     ------------->
  // 获取oss STS 授权
  @GET("/oss/sts")
  Future<OssStsResp> ossSts();
  
  // <------------      UserController     ------------->
  // 用户密码登录
  @POST("/user/loginByPwd")
  Future<LoginResp> loginByPwd(@Body() LoginReq req);

  // 用户注册
  @POST("/user/register")
  Future<LoginResp> register(@Body() RegisterReq req);

  // 用户退出登录
  @GET("/user/logout")
  Future<CommonResp> logout();

  // 用户修改密码
  @POST("/user/updatePwd")
  Future<CommonResp> updatePwd(@Body() UpdatePasswordReq req);
  
  // 更新用户信息
  @POST("/user/update")
  Future<CommonResp> updateUserInfo(@Body() User user);

  
  
  // <------------      PurchaseController     ------------->
  // 添加采购记录
  @POST("/purchase/add")
  Future<PurchaseItemResp> addPurchase(@Body() PurchaseEntity req);

  // 删除采购记录
  @DELETE("/purchase/purchase/{id}")
  Future<CommonResp> deletePurchase(@Path("id") int int);
  
  // 编辑采购记录
  @POST("/purchase/editPurchase")
  Future<PurchaseItemResp> editPurchase(@Body() PurchaseEntity req);

  // 获取最近添加的产品名称
  @GET("/purchase/purchaseItemName")
  Future<RecentNamesListResp> recentNames({@Query("count") int count = 5});

  // 获取采购的统计信息
  @POST("/purchase/purchaseStatistics")
  Future<PurchaseStatisticsResp> purchaseStatistics(@Body() PurchaseListReq req);

  // 获取采购列表
  @POST("/purchase/purchaseList")
  Future<PurchaseListResp> purchaseList(@Body() PurchaseListReq req);




  // <------------      SalesController     ------------->
  // 添加销售记录
  @POST("/sales/add")
  Future<AddSalesResp> addSales(@Body() SalesEntity req);

  // 获取销售统计
  @POST("/sales/salesStatistics")
  Future<SalesStatisticsResp> salesStatistics(@Body() SalesListReq req);

  // 获取销售列表
  @POST("/sales/salesList")
  Future<SalesListResp> salesList(@Body() SalesListReq req);

  // 获取销售最近添加的产品名称
  @GET("/sales/salesItemName")
  Future<RecentNamesListResp> salesRecentItemName({@Query("count") int count = 5});

  // 编辑销售记录
  @POST("/sales/editSales")
  Future<SalesItemResp> editSales(@Body() SalesEntity req);


}